package com.itheima10;

import jdk.swing.interop.SwingInterOpUtils;

import java.math.BigDecimal;

/**
 * @author Xiao
 * @date 2021/7/20
 */
public class BigDecimalDemo02 {
    /**
     * BigDecimal
     */
    public static void main(String[] args) {
        BigDecimal bd1 = new BigDecimal("0.3");
        BigDecimal bd2 = new BigDecimal("4");
        //参数一：参与运算的另一个对象
        //参数二：小数点后精确位数
        //参数三：舍入模式
                //进一法：BigDecimal.ROUND_HALF_UP
                //去尾法：BigDecimal.ROUND_FLOOR
                //四舍五入法：BigDecimal.ROUND_HALF_UP
        BigDecimal d1 = bd1.divide(bd2, 2, BigDecimal.ROUND_HALF_UP);   //0.08
        BigDecimal d2 = bd1.divide(bd2, 2, BigDecimal.ROUND_FLOOR);     //0.07
        BigDecimal d3 = bd1.divide(bd2, 2, BigDecimal.ROUND_HALF_UP);   //0.08
        System.out.println(d1);
        System.out.println(d2);
        System.out.println(d3);
        //报错：ArithmeticException → 算术条件异常
//        BigDecimal divide = bd1.divide(bd2);
//        System.out.println(divide);
    }
}